package com.company.nuwa.common.constants;


import com.company.nuwa.common.enumration.DomainScope;

import java.text.MessageFormat;

/**
 * All rights Reserved, Designed By Trump
 *
 * @version V1.0
 * @Description:
 * @author: Trump
 * @date: 2020/3/24
 * @Copyright: 2020 Trump Inc. All rights reserved.
 */
public class BasicConstants {

    /**
     * redis key 分割符
     */
    public static final String KEY_SPLIT = ":";

    /**
     * 每页默认显示记录数
     */
    public static final int DEFAULT_PAGE_SIZE = 20;
    /**
     * 默认第一页
     */
    public static final int DEFAULT_CURRENT_PAGE = 1;

    /**
     * 默认30分钟，可以根据实际使用场景进行调整
     */
    public static final long JWT_DEFAULT_TTL = 7 * 3600000 * 24;

    /**
     * 默认为一周
     */
    public static final long JWT_DEFAULT_REFRESH_TOKEN_TTL = 7 * 3600000 * 24;

    /**
     * 发行机构
     */
    public static final String JWT_ISSUER = "live-trump";

    /**
     * 秘钥
     */
    public static final String JWT_SECRET = "abcdefghijklmnopqrstuvwxyz1234567890";

    /**
     * 盐默认长度
     */
    public static final int DEFAULT_SALT_LEN = 6;

    /**
     * 请求头 token
     * <p>
     * 建议使用
     *
     * @see Headers#X_ACCESS_TOKEN
     */
    @Deprecated
    public static final String X_ACCESS_TOKEN = "X-ACCESS-TOKEN";

    /**
     * 网关下发请求头
     * <p>
     * 建议使用
     *
     * @see Headers#AUTHORIZATION_USER_ID
     */
    @Deprecated
    public static final String AUTHORIZATION_USER_ID = "Authorization-UserId";

    /**
     * 商家编号
     * <p>
     * 建议使用
     *
     * @see Headers#MERCHANT_ID
     */
    @Deprecated
    public static final String MERCHANT_ID = "merchantId";

    /**
     * 登录生成jwt模板
     */
    @Deprecated
    public static final String LOGIN_PATTERN_JWT = "{0}:jwt:{1}";

    /**
     * jwt key模版
     * {0}-商家编号
     * {1}-作用域(app、obs、web) {@link DomainScope}
     * {2}-用户身份
     */
    public static final String PATTERN_JWT_KEY = "jwt:{0}:{1}:{2}";

    /**
     * token状态：被封禁
     */
    public static final int TOKEN_STATUS_DISABLE = 1;

    /**
     * token状态：可用
     */
    public static final int TOKEN_STATUS_AVAILABLE = 0;

    /**
     * 获取jwt key
     *
     * @param merchantId
     * @param domainScope
     * @param userId
     * @return
     */
    public static String getJwtKey(String merchantId, DomainScope domainScope, Object userId) {
        return MessageFormat.format(BasicConstants.PATTERN_JWT_KEY, merchantId, domainScope.getCode(), String.valueOf(userId));
    }

}
